package com.credithc.eagleeye.config;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
 * 描 述: 鹰眼监控配置<br/>
 * 作 者: zhangjin<br/>
 * 创 建：2016年06月07日<br/>
 * 版 本：v1.0.0<br>
 * <p/>
 * 历 史: (版本) 作者 时间 注释 <br/>
 */
public class EagleESMonitorConfig {
    protected static final String filename = "property/eagle-monitor-config.properties";

    public synchronized static void loadConfig() {
        loadConfig(filename);
    }

    public synchronized static void loadConfig(String filePath) {

        Properties localProperties = new Properties();
        try (InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath)) {
            if (null == input) {
                throw new RuntimeException(filePath);
            }
            localProperties.load(input);

            EAGLE_MONITOR_ES_INDEX = localProperties.getProperty("eagle_monitor_es_index", "ice-monitor");
            EAGLE_MONITOR_ES_TYPE = localProperties.getProperty("eagle_monitor_es_type", "ice");
            EAGLE_MONITOR_TRY_TIMES = Integer.parseInt(localProperties.getProperty("eagle_monitor_try_times", "3"));
            EAGLE_MONITOR_ES_BATCH_SIZE = Integer.parseInt(localProperties.getProperty("eagle_monitor_es_batch_size", "100"));
            EAGLE_MONITOR_SLEEP_MILLIS = Integer.parseInt(localProperties.getProperty("eagle_monitor_sleep_millis", "5000"));
            EAGLE_MONITOR_ES_ADDRESS = localProperties.getProperty("eagle_monitor_es_address", "");
            EAGLE_MONITOR_ENABLE = Boolean.valueOf(localProperties.getProperty("eagle_monitor_enable", "true"));
            EAGLE_MONITOR_ALERT_MINUTE_AGO = Integer.parseInt(localProperties.getProperty("eagle_monitor_alert_minute_ago", "2"));
            EAGLE_MONITOR_ES_CLUSTER_NAME = localProperties.getProperty("eagle_monitor_es_cluster_name", "");
            EAGLE_MONITOR_ES_SHIELD_USER = localProperties.getProperty("eagle_monitor_es_shield_user", "");
        } catch (final IOException ex) {
            throw new RuntimeException(String.format("can not found config file:[%s]", ex.getMessage()));
        }

    }

    /** ES的索引名 */
    public static String EAGLE_MONITOR_ES_INDEX = "eagle-monitor";

    /** ES的文档类型 */
    public static String EAGLE_MONITOR_ES_TYPE = "eagle";

    /** 最多尝试次数 */
    public static int EAGLE_MONITOR_TRY_TIMES = 3;

    /** 批量提交次数 */
    public static int EAGLE_MONITOR_ES_BATCH_SIZE = 100;

    /** 每次提交后休眠毫秒数 */
    public static int EAGLE_MONITOR_SLEEP_MILLIS = 5000;

    public static String EAGLE_MONITOR_ES_ADDRESS="";

    /**是否生效*/
    public static boolean EAGLE_MONITOR_ENABLE=true;

    /**预警2分钟内*/
    public static int EAGLE_MONITOR_ALERT_MINUTE_AGO=2;
    /**ES集群名称*/
    public static String EAGLE_MONITOR_ES_CLUSTER_NAME="";
    /**用户名密码*/
    public static String EAGLE_MONITOR_ES_SHIELD_USER="";

}

